package net.cathackers.devel.scmp.chat.impl.xmpp.iqcomponent;

import net.cathackers.devel.scmp.chat.impl.xmpp.iqcomponent.interfaces.IQHandlerClassifier;
/**
 *this class is responsible for classifying IQPackets according to name and namespace 
 *
 */
public class IQHandlerClassifierImpl implements IQHandlerClassifier {
    private String name_;
    private String namespace_;
    
    public IQHandlerClassifierImpl(String name, String namespace) {
	this.name_ = name;
	this.namespace_ = namespace;
    }
    /**
     * @return namespace
     */
    @Override
    public String getNS() {
	return namespace_;
    }

    /**
     * @return name
     */
    @Override
    public String getName() {
	return name_;
    }
    
    @Override
    public int hashCode() {
	/**
	 *  it's safe to use the hashCode of the namespace only
	 * because we will never see the same namespace used for different handlers.
	 */
	
        return namespace_.hashCode();
    }
    
    @Override
    public boolean equals(Object obj) {
	boolean ret = false;
	if (obj instanceof IQHandlerClassifier) {
	    IQHandlerClassifier newObj = (IQHandlerClassifier)obj;
	    if (newObj.getName().equalsIgnoreCase(name_) && newObj.getNS().equalsIgnoreCase(namespace_)) {
		ret = true;
	    }
	}else {
	    ret = super.equals(obj);
	}
	return ret;
    }
    
    @Override
    public String toString() {
        return name_  + "<>" + namespace_;
    }

}
